package Servlet;

import javaBean.Detail;
import useBean.DetailDB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * <p>Title: DeleteReplyServlet</p>
 * <p>author 12427</p>
 *
 * @version ver1.0
 * @date 2021/12/22 15:25
 */
@WebServlet("/DeleteReplyServlet")
public class DeleteReplyServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        String url ="/MessageDetail.jsp";

        try {
            deleteReplyMessage(request,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
        List<Detail> dL = null;
        try {
            dL = DetailDB.selectU();
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.setAttribute("DetailList", dL);
        getServletContext().getRequestDispatcher(url).forward(request, response);

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        String action = request.getParameter("action");
        String url ="/MessageDetail.jsp";


        try {
            deleteReplyMessage(request,response);
        } catch (Exception e) {
            e.printStackTrace();
        }

        List<Detail> dL = null;
        try {
            dL = DetailDB.selectU();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        request.setAttribute("DetailList", dL);
        request.getServletContext().getRequestDispatcher(url).forward(request, response);
    }

    private void deleteReplyMessage(HttpServletRequest request,HttpServletResponse response) throws Exception {
        String cid = request.getParameter("cid") ;
        DetailDB.deleteDetail(cid);
    }

}
